package service.xml;

import java.util.Iterator;
import java.util.List;

/*
 * Xml
 *
 * Descripción: Esta clase Xml
 *
 * Autor: Erik
 *
 * Versión: 0.1
 *
 * Fecha: 01/04/14
 *
 */
public class Xml {

    public Xml() {
    }

    public StringBuilder toXml(List<Object[]> list) {

        StringBuilder sb = new StringBuilder("<bean>");
        if ((list != null) && (list.size() == 2)) {
            Object[] ftil = (Object[]) list.get(0);
            Object[] fdat = (Object[]) list.get(1);

            for (int i = 0; i < ftil.length; i++) {
                sb.append("<nodo id=\"").append(ftil[i]).append("\">");
                Object campo = (fdat[i] == null) ? "" : fdat[i];
                System.out.println("" + campo.toString());
                sb.append(campo);
                sb.append("</nodo>");
            }
        }
        sb.append("</bean>");

        return sb;
    }

    public StringBuilder toXml2(List<Object[]> list) {

        StringBuilder sb = new StringBuilder("<bean>");
        Iterator i = list.iterator();
        while (i.hasNext()) {
            Object[] objects = (Object[]) i.next();
            for (int j = 0; j < objects.length; j++) {
                sb.append("<nodo id=\"").append("fecha").append("\">");
                sb.append(objects[j]);
                sb.append("</nodo>");
            }
        }
        sb.append("</bean>");

        return sb;
    }
}
